//
//  ViewController.m
//  SouFunMainAPP
//
//  Created by 许博 on 16/5/18.
//  Copyright © 2016年 许博. All rights reserved.
//

#import "ViewController.h"



@interface ViewController () <UITableViewDelegate,UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *tableView;

@property (nonatomic,strong) NSArray *dataSource;
@end

@implementation ViewController

- (NSArray *)dataSource {
    if (_dataSource==nil) {
        _dataSource = @[
                        @{
                            @"projectName": @"新房模块",
                            @"controllerName": @"SouFunXFListController"
                            },
                        @{
                            @"projectName": @"二手房模块",
                            @"controllerName": @"SouFunEsfController"
                            },
                        @{
                            @"projectName": @"租房模块",
                            @"controllerName": @"SouFunZFController"
                            },
                        @{
                            @"projectName": @"金融模块",
                            @"controllerName": @"SouFunJRHomeController"
                            },
                        ];
                        // 这里感觉可以配置一个plist文件，调用任何模块的方法去显示想要的内容
                        // 并且把这个plist文件放在服务器上更新，实现主页显示
        
    }
    
    return _dataSource;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataSource.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *ID = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell==nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];
    }
    NSString *name = [self.dataSource[indexPath.row] valueForKey:@"projectName"];
    cell.textLabel.text = name;
    cell.backgroundColor = [UIColor colorWithRed:arc4random_uniform(256)/255.0 green:arc4random_uniform(256)/255.0 blue:arc4random_uniform(256)/255.0 alpha:1.0];
    return cell;
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    NSString *vcName = [self.dataSource[indexPath.row] valueForKey:@"controllerName"];
    Class vc = NSClassFromString(vcName);
    
    [self.navigationController pushViewController:[[vc alloc] init] animated:YES];
    
}


@end
